package cn.edu.scau.cmi.linhongxin.summary;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.linhongxin.client.AdapterClient;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class SummaryController implements Initializable{
	@FXML
	private Button experimentOne;
	@FXML
	private Button experimentTwo;
	@FXML
	private Button experimentThree;
	@FXML
	private Button simpleFactory;
	@FXML
	private Button factory;
	@FXML
	private Button abstractFactory;
	@FXML
	private Button safeComposite;
	@FXML
	private Button cosistentComposite;
	@FXML
	private Button hibernate;
	@FXML
	private Button spring;
	public void showStage(String path, String title) throws IOException {
		Parent root = FXMLLoader.load(getClass().getResource(path));
		Stage stage = new Stage();
		stage.setTitle(title);
		stage.setScene(new Scene(root));
		/*if(title.equals("Spring") || title.equals("Hibernate")) {
			stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
				@Override
				public void handle(WindowEvent event) {
					HibernateSessionFactory.getSessionFactory().close();				
				}			
			});
		}*/
		stage.show();
	}	
	public void experimentOneClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/interProgramming/InterProgrammingStage.fxml", "接口编程");
	}
	public void experimentTwoClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/singleton/Singleton.fxml", "单例和多例模式");
	}
	public void adapterClick(ActionEvent e) throws Exception{
		AdapterClient aClient = new AdapterClient();
		aClient.start(new Stage());		
	}
	public void simplyFactoryClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/simpleFactoryMethod/SimpleFactoryMethodStage.fxml", "简单工厂模式");
	}
	public void factoryClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/factory/FactoryStage.fxml", "工厂模式");
	}
	public void abstractFactoryClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/abstractFactory/AbstractFactoryStage.fxml", "抽象工厂模式");
	}
	public void safeCompositeClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/composite/safe/SafeStage.fxml", "安全型组合模式");
	}
	public void cosistentCompositeClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/composite/cosistent/CosistentStage.fxml", "一致型组合模式");
	}	
/*	public void hibernateClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/orm/hibernate/HibernateStage.fxml", "Hibernate");
	}	
	public void springClick(ActionEvent e) throws IOException {
		showStage("/cn/edu/scau/cmi/linhongxin/spring/view/SpringStage.fxml", "Spring");
	}	
*/
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub

	}
}
